package properties;

import lombok.val;
import lombok.var;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.Iterator;
import java.util.Properties;
import java.util.Set;

/**
 * @description: ToDo
 * @author: marin
 * @time: 2020/7/2 19:11
 */
public class PorpertiesInputstream {
    public static void main(String[] args) {
        try {
            Properties properties = new Properties();
            properties.load(new FileReader("hello.txt"));
            Set<String> props = properties.stringPropertyNames();
            //set遍历的三种方式：1.增强for循环 2.迭代遍历 3.toArray方式遍历
            //增强for循环遍历
            for (String prop:props){
                System.out.println(prop +":"+properties.getProperty(prop));
            }
            //迭代遍历
            Iterator<String> iterator = props.iterator();
            while(iterator.hasNext()){
                String str = iterator.next();
                System.out.println(str+":"+properties.getProperty(str));
            }
            //toArray方式遍历
            Object[] objects = props.toArray();
            for (int i=0;i<objects.length;i++) {
                System.out.println(objects[i]+":"+properties.get(objects[i]));
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
